<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>和暖心后台管理系统</title>
	<!-- 依 赖 样 式 -->
	<link rel="stylesheet" href="component/pear/css/pear.css" />
	<!-- 加 载 样 式 -->
	<link rel="stylesheet" href="admin/css/loader.css" />
	<!-- 布 局 样 式 -->
	<link rel="stylesheet" href="admin/css/admin.css" />
	<link rel="stylesheet" href="component/elementUI/index.css">
	<link rel="icon" href="favicon.ico" type="image/x-icon">
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
	<style>
		.el-dialog__body {
			padding: 20px;
		}
	</style>
</head>
<!-- 结 构 代 码 -->

<body class="layui-layout-body pear-admin">
	<!-- 布 局 框 架 -->
	<div id="app" class="layui-layout layui-layout-admin">
		<!-- 顶 部 样 式 -->
		<div class="layui-header">
			<!-- 菜 单 顶 部 -->
			<div class="layui-logo">
				<!-- 图 标 -->
				<img class="logo">
				<!-- 标 题 -->
				<span class="title"></span>
			</div>
			<!-- 顶 部 左 侧 功 能 -->
			<ul class="layui-nav layui-layout-left">
				<li class="collapse layui-nav-item"><a href="#" class="layui-icon layui-icon-shrink-right"></a></li>
				<li class="refresh layui-nav-item"><a href="#" class="layui-icon layui-icon-refresh-1" loading=600></a>
				</li>
			</ul>
			<!-- 多 系 统 菜 单 -->
			<div id="control" class="layui-layout-control"></div>
			<!-- 顶 部 右 侧 菜 单 -->
			<ul class="layui-nav layui-layout-right">
				<li class="layui-nav-item layui-hide-xs"><a href="#"
					class="menuSearch layui-icon layui-icon-search"></a></li>
				<li class="layui-nav-item layui-hide-xs"><a href="#"
					class="fullScreen layui-icon layui-icon-screen-full"></a>
				</li>
				<li class="layui-nav-item layui-hide-xs"><a href="javascript:;"
					class="layui-icon layui-icon-website"></a></li>
				<li class="layui-nav-item layui-hide-xs message"></li>
				<li class="layui-nav-item user">
					<!-- 头 像 -->
					<a class="layui-icon layui-icon-username" href="javascript:;"></a>
					<!-- 功 能 菜 单 -->
					<dl class="layui-nav-child">
						<dd><a href="javascript:void(0);" user-menu-url="view/system/person/index.html" user-menu-id="2"
								user-menu-title="基本资料">基本资料</a></dd>
						<dd><a href="javascript:void(0);" @click="handle">修改密码</a></dd>
						<dd><a href="javascript:void(0);" class="logout">注销登录</a></dd>
					</dl>
				</li>
				<!-- 主 题 配 置 -->
				<li class="layui-nav-item setting"><a href="#" class="layui-icon layui-icon-more-vertical"></a></li>
			</ul>
		</div>
		<!-- 侧 边 区 域 -->
		<div ref="side" class="layui-side layui-bg-black">
			<!-- 菜 单 顶 部 -->
			<div class="layui-logo">
				<!-- 图 标 -->
				<img class="logo">
				<!-- 标 题 -->
				<span class="title"></span>
			</div>
			<!-- 菜 单 内 容 -->
			<div class="layui-side-scroll">
				<div id="sideMenu"></div>
			</div>
		</div>
		<!-- 视 图 页 面 -->
		<div class="layui-body">
			<!-- 内 容 页 面 -->
			<div id="content"></div>
		</div>
		<!-- 页脚 -->
		<div class="layui-footer layui-text">
			<span class="left">
				Released under the MIT license.
			</span>
			<span class="center"></span>
			<span class="right">
				Copyright © 2021-2022 pearadmin.com
			</span>
		</div>
		<!-- 遮 盖 层 -->
		<div class="pear-cover"></div>
		<!-- 加 载 动 画 -->
		<div class="loader-main">
			<!-- 动 画 对 象 -->
			<div class="loader"></div>
		</div>
		<!-- 修 改 密 码 弹 窗 -->
		<el-dialog id="dialog" title="修改密码" :visible.sync="visibleDialog" width="450px" destroy-on-close :close-on-click-modal="false">
			<el-form ref="contract" label-width="80px" label-position="right" :model="form" :rules="rules">
				<el-form-item prop="old_Pass_Word" label="密码">
					<el-input v-model.trim="form.old_Pass_Word" placeholder="请输入密码"></el-input>
				</el-form-item>
				<el-form-item prop="new_Pass_Word" label="新密码">
					<el-input v-model.trim="form.new_Pass_Word" placeholder="请输入新密码"></el-input>
				</el-form-item>
				<el-form-item prop="submit_Pass_Word" label="确认密码">
					<el-input v-model.trim="form.submit_Pass_Word" placeholder="再次确认密码"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="handle">取消</el-button>
				<el-button :loading="loading" type="primary" @click="submitForm('contract')">确定</el-button>
			</span>
		</el-dialog>
	</div>
	<!-- 移 动 端 便 捷 操 作 -->
	<div class="pear-collapsed-pe collapse">
		<a href="#" class="layui-icon layui-icon-shrink-right"></a>
	</div>
	<!-- 依 赖 脚 本 -->
	<script type="text/javascript" src="component/layui/layui.js"></script>
	<script type="text/javascript" src="component/pear/pear.js"></script>
	<script type="text/javascript" src="utils/jquery.min.js"></script>
	<script type="text/javascript" src="utils/jquery.cookie.js"></script>
	<script type="text/javascript" src="utils/vue.min.js"></script>
	<script type="text/javascript" src="component/elementUI/index.js"></script>
	<script type="text/javascript" src="config/config.js"></script>
	<script type="text/javascript" src="utils/utils.js"></script>
	<script type="text/javascript" src="utils/ID_Validity.js"></script>
	<!-- 框 架 初 始 化 -->
	<script>
		layui.use(['admin', 'jquery', 'popup', 'drawer'], function () {
			var $ = layui.jquery;
			var admin = layui.admin;
			var popup = layui.popup;
			// var convert = layui.convert;
			//获取角色身份
			let title = "和 暖 心 平 台";
			let data = `${BASE_URL2}/generalBusiness/getUserMenu?UserName=${getCookie('user')}`;
			let id = "BASE00000000005";
			// let href = "view/tool/base_config/index.html";
			let href = "view/home/index.html";
			if (getCookie('role')) {//角色是否存在
				let roleObj = JSON.parse(getCookie('role'));
				if (roleObj.role == 'supplier') {
					title = "供 应 商 发 货"
					href = "view/tripartite/supplier_order/index.html";
				} else if (roleObj.role == 'firstparty') {
					title = "甲 方 对 帐"
					href = "view/tripartite/firstparty_user/index.html";
				}
				data = roleObj.data;
				id = 1;
			}
			admin.setConfigType("jsonstring");
			admin.setConfigPath({
				"logo": {
					"title": title,
					"image": "admin/images/logo.png"
				},
				"menu": {
					"data": data,
					"method": "GET",
					"accordion": true,
					"collapse": false,
					"control": false,
					"controlWidth": 500,
					"select": "10",
					"async": true,
				},
				"tab": {
					"enable": true,
					"keepState": true,
					"session": false,
					"preload": false,
					"max": "30",
					"index": {
						"id": "1",
						"href": href,
						"title": "首页"
					}
				},
				"theme": {
					"defaultColor": "2",
					"defaultMenu": "dark-theme",
					"defaultHeader": "light-theme",
					"allowCustom": true,
					"banner": false
				},
				"colors": [
					{
						"id": "1",
						"color": "#2d8cf0",
						"second": "#ecf5ff"
					},
					{
						"id": "2",
						"color": "#36b368",
						"second": "#f0f9eb"
					},
					{
						"id": "3",
						"color": "#f6ad55",
						"second": "#fdf6ec"
					},
					{
						"id": "4",
						"color": "#f56c6c",
						"second": "#fef0f0"
					},
					{
						"id": "5",
						"color": "#3963bc",
						"second": "#ecf5ff"
					}
				],
				"other": {
					"keepLoad": "1200",
					"autoHead": false,
					"footer": false
				},
				"header": {
					"message": "admin/data/message.json"
				}
			});
			
			// admin.setConfigType("yml");
			// admin.setConfigPath("config/pear.config.yml");
			admin.render();
			// 登出逻辑
			admin.logout(function () {
				removeCookie('token');
				removeCookie('user');
				removeCookie('role')
				popup.success("注销成功", function () {
					location.href = "login.html";
				})
				// 注销逻辑 返回 true / false
				return true;
			})
			// 消息点击回调
			admin.message(function (id, title, context, form) { });
		})
		new Vue({
			el: '#app',
			data() {
				return {
					visibleDialog: false,
					loading: false,
					form: {
						old_Pass_Word: '',
						new_Pass_Word: '',
						submit_Pass_Word: '',
					},
					rules: {
						old_Pass_Word: [{
							required: true,
							validator: (rule, value, callback) => {
								if (validatePassword(this.form.old_Pass_Word)) {
									callback(new Error(validatePassword(this.form.old_Pass_Word, '请输入旧密码')));
								} else {
									callback();
								}
							},
							trigger: 'blur'
						}],
						new_Pass_Word: [{
							required: true,
							validator: (rule, value, callback) => {
								if (validatePassword(this.form.new_Pass_Word)) {
									callback(new Error(validatePassword(this.form.new_Pass_Word, '请输入新密码')));
								} else if (this.form.old_Pass_Word == this.form.new_Pass_Word) {
									callback(new Error('新密码不能和原密码一致'));
								} else {
									callback();
								}
							},
							trigger: 'blur'
						}],
						submit_Pass_Word: [{
							required: true,
							validator: (rule, value, callback) => {
								if (validatePassword(this.form.submit_Pass_Word)) {
									callback(new Error(validatePassword(this.form.submit_Pass_Word, '请再次输入密码')));
								} else if (this.form.new_Pass_Word != this.form.submit_Pass_Word) {
									callback(new Error('确认密码与新密码不一致'));
								} else {
									callback();
								}
							},
							trigger: 'blur'
						}],
					},
				}
			},
			methods: {
				handle() {
					this.visibleDialog = !this.visibleDialog;
				},
				submitForm(formName) {
					const that = this
					this.$refs[formName].validate((valid) => {
						if (valid) {
							that.loading = true;
							$.ajax({
								headers: requestHeaders(),
								url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
								type: 'POST',
								data: {
									Data: 'base_system_user_info',
									Condition: "User_Number='" + getCookie('user') + "' and Pass_Word='"+ that.form.old_Pass_Word +"'",
								},
								success: function (base_system_user_info) {
									if (base_system_user_info.length == 1) {
										base_system_user_info[0].Pass_Word = that.form.new_Pass_Word
										$.ajax({
											headers: requestHeaders(),
											url: `${BASE_URL2}/generalBusiness/generalSave`,
											type: 'POST',
											data: {
												Data: JSON.stringify({ 
													Modify: { base_system_user_info } ,
													Add: { base_operation_log:[generateLog('修改当前登录账号的密码', '平台端操作', 'base_system_user_info', JSON.stringify({  Modify: { base_system_user_info } }))] }
												})
											},
											success: function (res) {
												if (res.Status === 'success') {
													that.$message.success("修改成功,需重新登录");
													that.visibleDialog = false;
													const timer = setTimeout(() => {
														clearTimeout(timer);
														removeCookie('token');
														removeCookie('user');
														removeCookie('role');
														location.href = "login.html";
													},1000)
												} else {
													that.$message.error("系统繁忙，请稍后再试")
												}
											},
											complete: function (XMLHttpRequest) {
												that.loading = false;
												requestPretreatment(XMLHttpRequest, false, (Status) => {
													if (Status == "error") {
														that.$message.error("系统繁忙，请稍后再试");
													}
												});
											},
											dataType: "json"
										})
									} else {
										that.loading = false;
										that.$message.error("密码错误");
									}
								},
								complete: function (XMLHttpRequest) {
									requestPretreatment(XMLHttpRequest, false, (Status) => {
										if (Status == "error") {
											that.$message.error("系统繁忙，请稍后再试");
										}
									});
								},
								dataType: "json"
							})
						}
					});
				},
			},
			mounted() {
				const observer = new ResizeObserver(entries => {
					for (let entry of entries) {
						document.getElementById('dialog').style.left = entry.contentRect.width + 'px';
					}
				})
				observer.observe(this.$refs.side)
			}
		})
	</script>
</body>

</html>